DEMO: The noteOn, noteOff, and playNote Methods

The Music Object API's noteOn, noteOff, and playNote methods let you trigger and stop musical notes from virtually any user interaction within a page. And the great thing about musical notes is that they are free, with no downloads of audio or music files required. The instrument sounds, like the Groovoids, are built directly into the Beatnik Player's soundbank.

So Many Sounds, So Few Buttons!

Musical notes play through the Beatnik Player's software synthesizer, on any one of the many instrument sounds in the player's soundbank. In case you thought that 72 Groovoids was a lot, the Beatnik Player soundbank contains an incredible 256 musical instrument sounds, as well as 109 percussion sounds. The percussion sounds are particularly useful for sonifying user interface elements on Web pages - ideal for link click sounds, button click sounds, link mouseover sounds, form submit sounds, and more.

Check out the buttons below. Each button has a different click sound, thanks to sounds chosen from the Beatnik Player's percussion banks. To the right of each button is the source code of the playNote method call for each button. Go on and click 'em...

 myMusicObject.playNote (1,0,128+27,51,127,1000) 
 myMusicObject.playNote (1,1,128+88,66,127,1000) 
 myMusicObject.playNote (1,0,128+75,60,127,1000) 
 myMusicObject.playNote (1,0,128+85,60,127,1000) 
 myMusicObject.playNote (1,1,128+46,79,127,1000) 
The Highs and the Lows

Your palette of sounds gets extended even further when you take musical instrument sounds and play them at different pitches. Each instrument sound can be played at 128 different pitches!

The following buttons all play the Beatnik Player's castanets percussion sound. However, completely different effects are achieved simply by playing the musical notes at different pitches. Using only one sound from the soundbank, each button now has its own distinctive click effect. To the right of each button is the code used to produce the sound for the button.

 myMusicObject.playNote (1,0,128+85,'A2',127,1000) 
 myMusicObject.playNote (1,0,128+85,'G3',127,1000) 
 myMusicObject.playNote (1,0,128+85,'F4',127,1000) 
 myMusicObject.playNote (1,0,128+85,'D#5',127,1000) 
 myMusicObject.playNote (1,0,128+85,'C#6',127,1000) 
 myMusicObject.playNote (1,0,128+85,'B6',127,1000) 
Roll Your Own Behaviors

With the Music Object API, you get full control to make the kind of musical behaviors that you want for your Web page elements. Combine the noteOn, noteOff, and playNote methods to create sonified links in an enormous number of different ways.

Take a look at the links below, for intance. Each link has its own unique sound for when you "mouse over" and for when you click. The "mouse over" sound plays for as long as you are over the link, and then stops as soon as you move the mouse away from the link. The "mouse over" sound also stops when you click on the link and the click sound is played. To the right of each sonified link is the source code used to create the musical behavior for the link. Try it out...

Just Some Link 1 <A
     HREF="javascript://"
     ONMOUSEOVER="myMusicObject.noteOn (1,1,50,51,127)"
     ONMOUSEOUT="myMusicObject.noteOff (1,51)"
     ONCLICK="
          myMusicObject.noteOff (1,51);
          myMusicObject.playNote (1,0,128+27,51,127,1000);
          return false
     "
>
     Just Some Link 1
</A>
Just Some Link 2 <A
     HREF="javascript://"
     ONMOUSEOVER="myMusicObject.noteOn (1,1,91,76,127)"
     ONMOUSEOUT="myMusicObject.noteOff (1,76)"
     ONCLICK="
          myMusicObject.noteOff (1,76);
          myMusicObject.playNote (1,0,128+75,60,127,1000);
          return false
     "
>
     Just Some Link 2
</A>
Just Some Link 3 <A
     HREF="javascript://"
     ONMOUSEOVER="myMusicObject.noteOn (1,1,86,36,127)"
     ONMOUSEOUT="myMusicObject.noteOff (1,36)"
     ONCLICK="
          myMusicObject.noteOff (1,36);
          myMusicObject.playNote (1,0,128+85,60,127,1000);
          return false
     "
>
     Just Some Link 3
</A>
Just Some Link 4 <A
     HREF="javascript://"
     ONMOUSEOVER="myMusicObject.noteOn (1,1,98,28,127)"
     ONMOUSEOUT="myMusicObject.noteOff (1,28)"
     ONCLICK="
          myMusicObject.noteOff (1,28);
          myMusicObject.playNote (1,1,128+46,79,127,1000);
          return false
     "
>
     Just Some Link 4
</A>
It All Stacks Up

Think that all the possibilities have been exhausted? Think again. There's no saying that you only need to play one musical note at a time. Even more complex textures can be achieved when you combine several musical notes, playing at different pitches, and playing different instrument sounds. You can even make your sonified elements musically correct by playing proper musical chords. Heck, you could even make it so that your Web page elements play chords that are in the same key as a piece of background music you are playing on the same page!!

As an example. try out the following sonified buttons below. In this case, each button is playing a musical chord using a specific instrument sound. To the right of each button is the source code used to create the chord effect for each button.

myMusicObject.playNote (1,0,98,40,127,1000);
myMusicObject.playNote (1,0,98,43,127,1000);
myMusicObject.playNote (1,0,98,47,127,1000);
myMusicObject.playNote (1,0,98,52,127,1000);
myMusicObject.playNote (1,0,98,55,127,1000);
myMusicObject.playNote (1,0,98,64,127,1000);
myMusicObject.playNote (1,0,97,40,127,1000);
myMusicObject.playNote (1,0,97,44,127,1000);
myMusicObject.playNote (1,0,97,47,127,1000);
myMusicObject.playNote (1,0,97,52,127,1000);
myMusicObject.playNote (1,0,97,56,127,1000);
myMusicObject.playNote (1,0,97,64,127,1000);
myMusicObject.playNote (1,0,95,41,127,1000);
myMusicObject.playNote (1,0,95,45,127,1000);
myMusicObject.playNote (1,0,95,47,127,1000);
myMusicObject.playNote (1,0,95,50,127,1000);
myMusicObject.playNote (1,0,95,52,127,1000);
myMusicObject.playNote (1,0,95,53,127,1000);
myMusicObject.playNote (1,0,93,41,127,1000);
myMusicObject.playNote (1,0,93,45,127,1000);
myMusicObject.playNote (1,0,93,47,127,1000);
myMusicObject.playNote (1,0,93,50,127,1000);
myMusicObject.playNote (1,0,93,55,127,1000);
myMusicObject.playNote (1,0,93,60,127,1000);
myMusicObject.playNote (1,0,92,43,127,1000);
myMusicObject.playNote (1,0,92,47,127,1000);
myMusicObject.playNote (1,0,92,50,127,1000);
myMusicObject.playNote (1,0,92,52,127,1000);
myMusicObject.playNote (1,0,92,55,127,1000);
myMusicObject.playNote (1,0,92,60,127,1000);
myMusicObject.playNote (1,0,88,45,85,1000);
myMusicObject.playNote (1,0,88,48,85,1000);
myMusicObject.playNote (1,0,88,52,85,1000);
myMusicObject.playNote (1,0,88,55,85,1000);
myMusicObject.playNote (1,0,88,57,85,1000);
myMusicObject.playNote (1,0,88,60,127,1000);
myMusicObject.playNote (1,0,78,48,70,1000);
myMusicObject.playNote (1,0,78,52,70,1000);
myMusicObject.playNote (1,0,78,55,70,1000);
myMusicObject.playNote (1,0,78,60,70,1000);
myMusicObject.playNote (1,0,78,64,70,1000);
myMusicObject.playNote (1,0,78,67,100,1000);
myMusicObject.playNote (1,1,93,48,90,1000);
myMusicObject.playNote (1,1,93,50,90,1000);
myMusicObject.playNote (1,1,93,55,90,1000);
myMusicObject.playNote (1,1,93,59,90,1000);
myMusicObject.playNote (1,1,93,62,90,1000);
myMusicObject.playNote (1,1,93,67,127,1000);
myMusicObject.playNote (1,1,49,38,127,1000);
myMusicObject.playNote (1,1,49,42,127,1000);
myMusicObject.playNote (1,1,49,45,127,1000);
myMusicObject.playNote (1,1,49,50,127,1000);
myMusicObject.playNote (1,1,49,66,70,1000);
myMusicObject.playNote (1,1,49,69,70,1000);
myMusicObject.playNote (1,0,52,38,100,1000);
myMusicObject.playNote (1,0,52,41,100,1000);
myMusicObject.playNote (1,0,52,45,100,1000);
myMusicObject.playNote (1,0,52,50,100,1000);
myMusicObject.playNote (1,0,52,65,100,1000);
myMusicObject.playNote (1,0,52,69,100,1000);

Of course, there's nothing to say that each one of the musical notes that makes up a chord should play exactly the same instrument sound. You can, most certainly, achieve a stunning variety of different sound textures by combining just the right instrument sounds at just the right pitches.

Randomize It!!!

Because the Music Object API is designed for a scripting environment, you can build up more complex behaviors using its basic methods. For example, you could quite easily create your own function for playing random musical notes within certain specified parameters. Beatnik Inc. has even gone to the trouble of offering more advanced features like this in ready-made Music Object extensions, such as Music Object Extension - Dynamic which offers a playRandomNote method.

To get an idea of the other cool things that can be done using musical notes, see the playRandomNote demo.